<template>
  <div class="middle maxi-1">
    <div class="z-1">
      <div class="z-2"></div>
      <div>已收藏的服务</div>
    </div>
    <div class="z-3">
      <div v-for="(item, index) in arrs" :key="index" class="zq-1">
        <el-icon class="no-inherit" @click="appends(item)" v-if="item.uid">
          <RemoveFilled />
        </el-icon>
        <img :src="item.icon" v-if="item.icon" class="imgs-2" />
        <img src="@/assets/head/t-1.png" v-else class="imgs-2" />
        <div class="te-x">{{ item.name }}</div>
      </div>
    </div>
    <div class="z-s">
      <div class="z-4">
        <div class="z-5"></div>
        <div>所有服务(161) 搜索</div>
      </div>
      <div class="z-6">
        <el-input v-model="input" placeholder="请输入应用名称" clearable />
        <el-button type="primary" @click="seek">搜索</el-button>
      </div>
    </div>
    <div class="z-7">
      <div class="z-8">
        <div class="zs-8">服务类型</div>
        <div class="zs-9">
          <div
            class="zs-91"
            v-for="(item, index) in listarr"
            :key="index"
            @click="add(item)"
            :class="{ active: antindex === index }"
          >
            <div>{{ item.name }}</div>
            <div>{{ item.appCount }}</div>
          </div>
        </div>
      </div>
      <div class="z-9">
        <div class="z-91" v-for="(item, index) in sum" :key="index">
          <el-icon class="no-inherit" @click="append(item)" v-if="!item?.uid">
            <CirclePlusFilled />
          </el-icon>
          <img :src="item.icon" v-if="item.icon" class="imgs-2" />
          <img src="@/assets/head/t-1.png" v-else class="imgs-2" />
          <div class="te-x">{{ item.name }}</div>
        </div>
      </div>
    </div>
    <div class="zs-1">
      <el-button type="primary" :icon="FolderOpened" @click="save"
        >保存</el-button
      >
    </div>
  </div>
</template>

<script lang="ts" setup>
import type { additionalProperties1, arrss2 } from '@/services/types/Applic'
import { FolderOpened } from '@element-plus/icons-vue'
import { saveCollect } from '@/services/Application'
import { ElMessage } from 'element-plus'
const input = ref('')

const props = defineProps<{
  listarr?: arrss2
  sum?: additionalProperties1
}>()
type addCollect = {
  appId: string
  appIds: Array<string>
}
const obj = ref<addCollect>({
  appId: '',
  appIds: []
})
const antindex = ref()
const arrs: any = ref([])
const append = (item: any) => {
  item.uid = 1
  arrs.value.push(item)
  obj.value.appIds.push(item.id)
}
const appends = (item: any) => {
  item.uid = 0
  arrs.value.splice(arrs.value.indexOf(item), 1)
  obj.value.appIds.splice(obj.value.appIds.indexOf(item.id), 1)
}
const emit = defineEmits<{
  (e: 'add', item: any): void
  (e: 'seek', input: string): void
}>()
const seek = () => {
  emit('seek', input.value)
}
const add = (item: any) => {
  if (!props.listarr) return
  antindex.value = props.listarr.indexOf(item)
  emit('add', item)
}
const save = async () => {
  const res = await saveCollect(obj.value)
  if (res.data) {
    ElMessage.success('保存成功')
  }
}
</script>

<style lang="scss" scoped>
.maxi-1 {
  box-sizing: border-box;
}
.z-1 {
  display: flex;
  padding: 10px 0;
  box-sizing: border-box;
}
.z-2 {
  width: 4px;
  height: 20px;
  background-color: #ffc107;
  margin-right: 10px;
}
.z-3 {
  width: 100%;
  min-height: 142px;
  border: 1px solid #e0e0e0;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
}
.z-4 {
  display: flex;
}
.z-5 {
  width: 4px;
  height: 20px;
  background-color: #ffc107;
  margin-right: 10px;
}
.z-6 {
  display: flex;
}
.z-s {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.z-7 {
  display: flex;
}
.z-8 {
  width: 300px;
  height: 400px;
  margin-right: 20px;
  border: 1px solid #e0e0e0;

  .zs-8 {
    width: 100%;
    height: 50px;
    text-align: center;
    line-height: 50px;
    border-bottom: 1px solid #e0e0e0;
  }
  .zs-9 {
    width: 100%;
    height: 340px;
    overflow-y: auto;
    .zs-91 {
      display: flex;
      justify-content: space-between;
      width: 100%;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #e0e0e0;
      padding: 0 10px;
      font-size: 14px;
      box-sizing: border-box;
      cursor: pointer;
    }
  }
}
.z-9 {
  width: 1000px;
  height: 400px;
  border: 1px solid #e0e0e0;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  .z-91 {
    width: 108px;
    height: 106px;
    margin: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background: #f1f1f1;
  }
}
.zs-1 {
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  padding: 10px;
}
.active {
  background: #1384e2;
  color: #fff;
}
.no-inherit {
  margin-left: 76px;
  color: #f55151 !important;
  background: #fff !important;
  cursor: pointer;
}
.zq-1 {
  width: 108px;
  height: 106px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  margin: 5px;
  background: #f1f1f1;
}
.imgs-2 {
  width: 51px;
  height: 51px;
}
.te-x {
  width: 80px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* 如果需要在文本溢出时显示省略号 */
}
</style>
